package com.gitee.dupe.authority.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.gitee.dolt.boot.service.SuperServiceImpl;
import com.gitee.dupe.authority.dao.RoleResourceMapper;
import com.gitee.dupe.authority.entity.RoleResource;
import com.gitee.dupe.authority.service.IRoleResourceService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author LYH
 * @since 2020-08-04
 */
@Service
public class RoleResourceServiceImpl extends SuperServiceImpl<RoleResourceMapper, RoleResource> implements IRoleResourceService {

    @Override
    public boolean removeByRoleId(Long id) {
        return remove(Wrappers.<RoleResource>lambdaQuery().eq(RoleResource::getRoleId, id));
    }

    @Override
    public List<RoleResource> findAllByRoleId(Long id) {
        return list(Wrappers.<RoleResource>lambdaQuery().eq(RoleResource::getRoleId, id));
    }

    @Override
    public boolean removeByRoleIdAndResourceIds(Long id, List<Long> resourceIds) {
        if (resourceIds.isEmpty()) {
            return true;
        }
        return remove(Wrappers.<RoleResource>lambdaQuery().eq(RoleResource::getRoleId, id).in(RoleResource::getResourceId, resourceIds));
    }
}
